//
//  MapGridView.m
//  iD20
//
//  Created by Andrew Spina on 5/22/10.
//  Copyright 2010 STScI. All rights reserved.
//

#import "MapGridViewUnitTest.h"


@implementation MapGridViewUnitTest

- (void) testInitialState {
	MapGridView* testMe = [[MapGridView alloc] initWithCoder: nil];
	STAssertTrue(30.0 == testMe.gridSize, @"Grid Size should be 30. Was: %f", testMe.gridSize);
	STAssertTrue(-1 == testMe.firstTapLocation.x, @"Start with a 'nil' tap location");
	STAssertTrue(-1 == testMe.firstTapLocation.y, @"Start with a 'nil' tap location");
	STAssertTrue(0 == testMe.offset.x, @"Start with a 'nil' tap location");
	STAssertTrue(0 == testMe.offset.y, @"Start with a 'nil' tap location");
	STAssertNil(testMe.firstReferencePoint, @"No reference point to start with %@", testMe.firstReferencePoint);
}

- (void) testDragAroundFirstPoint {
	MapGridView* testMe = [[MapGridView alloc] initWithCoder: nil];
	STAssertTrue(30.0 == testMe.gridSize, @"Grid Size should be 30. Was: %f", testMe.gridSize);
	[testMe firstTouchAtPoint:CGPointMake(0.0, 0.0)];
	[testMe secondTouchAtPoint:CGPointMake(60.0, 60.0)];
	STAssertTrue(testMe.firstReferencePoint.x == 0, @"First Point should be 0,0. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstReferencePoint.y == 0, @"First Point should be 0,0. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.secondTouchPoint.x == 2,@"Second Point should be 2,2. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.secondTouchPoint.y == 2,@"Second Point should be 2,2. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.firstTapLocation.x == 0, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	STAssertTrue(testMe.firstTapLocation.y == 0, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	[testMe firstTapDraggedTo: CGPointMake(0, 0)];
	STAssertTrue(0 == testMe.offset.x, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(0 == testMe.offset.y, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(testMe.firstReferencePoint.x == 0, @"First Point should be 0,0. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstReferencePoint.y == 0, @"First Point should be 0,0. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstTapLocation.x == 0, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	STAssertTrue(testMe.firstTapLocation.y == 0, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	[testMe firstTapDraggedTo: CGPointMake(30, 30)];
	STAssertTrue(0 == testMe.offset.x, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(0 == testMe.offset.y, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(testMe.firstReferencePoint.x == 1, @"First Point should advanced to 1,1 because the user dragged one square down and right. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstReferencePoint.y == 1, @"First Point should advanced to 1,1 because the user dragged one square down and right. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.secondTouchPoint.x == 3,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.secondTouchPoint.y == 3,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.firstTapLocation.x == 30, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	STAssertTrue(testMe.firstTapLocation.y == 30, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	[testMe firstTapDraggedTo: CGPointMake(0, 0)];
	STAssertTrue(0 == testMe.offset.x, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(0 == testMe.offset.y, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(testMe.firstReferencePoint.x == 0, @"First Point should be 0,0. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstReferencePoint.y == 0, @"First Point should be 0,0. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.secondTouchPoint.x == 2,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.secondTouchPoint.y == 2,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.firstTapLocation.x == 0, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	STAssertTrue(testMe.firstTapLocation.y == 0, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);	
	[testMe firstTapDraggedTo: CGPointMake(40, 40)];
	STAssertTrue(10 == testMe.offset.x, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(10 == testMe.offset.y, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(testMe.firstReferencePoint.x == 1, @"First Point should advanced to 1,1 because the user dragged one square down and right. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstReferencePoint.y == 1, @"First Point should advanced to 1,1 because the user dragged one square down and right. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.secondTouchPoint.x == 3,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.secondTouchPoint.y == 3,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.firstTapLocation.x == 30, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	STAssertTrue(testMe.firstTapLocation.y == 30, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);	
	[testMe firstTapDraggedTo: CGPointMake(46, 46)];
	STAssertTrue(-14 == testMe.offset.x, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(-14 == testMe.offset.y, @"MinimizeOffset shouldn't change offset in this situation");
	STAssertTrue(testMe.firstReferencePoint.x == 2, @"First Point should advanced to 1,1 because the user dragged one square down and right. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.firstReferencePoint.y == 2, @"First Point should advanced to 1,1 because the user dragged one square down and right. Was: %@", testMe.firstReferencePoint);
	STAssertTrue(testMe.secondTouchPoint.x == 4,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.secondTouchPoint.y == 4,@"Second Point should be stationary relative to point 1 and be at 3,3. Was: %@", testMe.secondTouchPoint);
	STAssertTrue(testMe.firstTapLocation.x == 60, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);
	STAssertTrue(testMe.firstTapLocation.y == 60, @"First Point should be 0,0. Was: %f, %f", testMe.firstTapLocation.x, testMe.firstTapLocation.y);	
}

- (void) testDragSecondPoint {
	//TODO Write some tests that verify zooming works.
}

@end
